{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python Epiphanies\n",
    "\n",
    "- Jupyter Notebooks at https://nbviewer.jupyter.org/\n",
    "- by William Yang\n",
    "- yywill@gmail.com\n",
    "- https://www.linkedin.com/in/yywill\n",
    "- Orignal Stuart Williams \n",
    "  - Python Epiphanies video at O'Reilly http://shop.oreilly.com/product/0636920039815.do\n",
    "\n",
    "> If in your use of Python you sometimes feel like an outsider, like you're missing the inside jokes, like you have most of the puzzle pieces but they don't quite fit together yet, or like there are parts of Python you just don't get, this may be a good tutorial for you.\n",
    "\n",
    "\n",
    "\n",
    "#### About Me\n",
    "- Architect at ZA Bank\n",
    "- 10 Years Java Experience\n",
    "- Python Backend Experience\n",
    "- Coaching at startups\n",
    "\n",
    "#### About You\n",
    "- What programming language(s) did you learn first?  Before or after Python?\n",
    "- How many years using Python?\n",
    "\n",
    "#### 忘掉变量(Variables) -- Python没有变量\n",
    "- 数学: 代数里面的可变的值，比如说x，叫做变量\n",
    "- 其他编程语言:\n",
    "  - 编译器的一块用来执行基于类型的指令(type-specific instructions)的内存区域\n",
    "  - 把变化数值写入这块内存区域\n",
    "  - 取别名(aliases)非常罕见\n",
    "- Python:\n",
    "  - 取自数学的原始定义\n",
    "  - 所以我们说 \"names\" and \"objects\" 不说 \"variables\"\n",
    "\n",
    "Example of type-specific instructions (from https://godbolt.org ):\n",
    "\n",
    "    int square(int a) {          int square(float a) {\n",
    "        return a * a;                return a * a;\n",
    "    }                            }\n",
    "    ----------------------       -----------------------\n",
    "    pushq   %rbp                 pushq   %rbp\n",
    "    movq    %rsp, %rbp           movq    %rsp, %rbp\n",
    "    movl    %edi, -4(%rbp)  !=   movss   %xmm0, -4(%rbp)\n",
    "    movl    -4(%rbp), %eax  !=   movss   -4(%rbp), %xmm0\n",
    "    imull   -4(%rbp), %eax  !=   mulss   -4(%rbp), %xmm0\n",
    "                            !=   cvttss2si %xmm0, %eax\n",
    "    popq    %rbp                 popq    %rbp\n",
    "    ret                          ret\n",
    "\n",
    "    imull is signed multiply (integer)\n",
    "    mulss is multiply scalar single-precision (float)\n",
    "\n",
    "#### About this Tutorial\n",
    "- 本课程重点讲述：面向对象 \n",
    "   - 举一反三达到中级水平\n",
    "- 本课程面向：接触过Python。知道def定义函数，知道if else语句，知道for循环，知道import，也知道简单的调用一两次API\n",
    "   - 但是：没法真的自己写出一个小工程(或：自己的小工程bug太多，不得不放弃）\n",
    "- 课程包含丰富的互动代码样例，不要指望自己可以全部理解（部分代码资深Python程序员也会弄错）\n",
    "- 5,6,7章节（装饰器，类第一公民以及迭代器）太难，可能也没有时间完成\n",
    "- 课程时间或许会达到3小时，如有问题请及时提问"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 + 2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'aa'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'a' + 'a'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for +: 'int' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-12-abf63472aed8>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;36m1\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m'a'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'"
     ]
    }
   ],
   "source": [
    "1 + 'a'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 类型怎么来的？\n",
    "\n",
    "![image](computer_architecture.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 让我们看看显微镜下初代CPU 8008 \n",
    "\n",
    "![image](cpu.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# X86 AMD64 指令集\n",
    "\n",
    "https://www.felixcloutier.com/x86/"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
